<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="Content-type" content="text/html; charset=utf-8">
		<link href="css/add.css" rel="stylesheet" type="text/css" />
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="css/style.css">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
		<script type="text/javascript" src="js/jquery-3.3.1.min.js" ></script>
		<script type="text/javascript" src="js/submit.js"></script>
		<script type="text/javascript" src="js/popups.js"></script>
		<script type="text/javascript">
			var ip;
			var surveyId,id;
			var mycars=new Array();
			$(function(){
				var configJson='js/confing.json'
				$.getJSON(configJson,function(data){
					ip=data.urlip;
					setSize();
       				addEventListener('resize',setSize);
       				var thisURL = document.URL;
					var getval =thisURL.split('?')[1];
					if(getval)
					{
						var showVal= getval.split("=")[1]; 
						id=showVal;
					 }
					else{
						surveyId="surveyId=0";
					}
					identi();
					from();
				});
            });
            function setSize() {
            	document.documentElement.style.fontSize = document.documentElement.clientWidth/750*100+'px';
            }
			var link={"党办校办": "http://dbxb.zjgsu.edu.cn/",
					"宣传部":"http://tzb.zjgsu.edu.cn/tzb/",  
					"统战部":" http://tzb.zjgsu.edu.cn/tzb/",
					"科研部":" http://kyc.zjgsu.edu.cn/default.html",
					"人事处":" http://rsc.zjgsu.edu.cn/",
					"资产处":" http://sbc.zjgsu.edu.cn/",
					"工会":" http://jgzj.zjgsu.edu.cn/",
					"杂志社 ":"http://zzs.zjgsu.edu.cn/CN/volumn/home.shtml",
					"档案馆":" http://zhdas.zjgsu.edu.cn/",
					"采购中心":" http://cgzx.zjgsu.edu.cn/",
					"学生处":"  http://xsc.zjgsu.edu.cn/",
					"保卫处":" http://bwc.zjgsu.edu.cn/",
					"团委":" http://youth.zjgsu.edu.cn/",
					"图书馆":" http://lib.zjgsu.edu.cn/",
					"网络中心":" http://nic.zjgsu.edu.cn/",
					"后勤中心":" http://hq.zjgsu.edu.cn/",
					"体工部":" http://tgb.zjgsu.edu.cn/",
					"国教学院":" http://sie.zjgsu.edu.cn/",
					"研究生院":" http://yjs.zjgsu.edu.cn/",
					"教务处":" http://jww.zjgsu.edu.cn/",
					"计财处":"  http://cwc.zjgsu.edu.cn/",
					"国际处":"  http://international.zjsu.edu.cn/",
					"招就处":" http://zhaoban.zjgsu.edu.cn/",
					"公共事务处":" http://zwc.zjgsu.edu.cn/",
					"浙商博物馆" :"http://www.zsbwg.org/",
					"创业学院" :"http://znq.zjgsu.edu.cn/"};
			var type=-1;
			$(document).on('click','#yes_btn',function exit(){
				$.ajax({
					type:"get",
					url:ip+"/logout",
					data:{},
					async:true,
					dataType: "json",
					xhrFields: {withCredentials: true},
      				crossDomain:true,
      				success:function(res)
      				{
      					window.location.href="login.html"
      				}
				});
			});
			function identi()
			{
				$.ajax({
     				type: "get",
   					url: ip+"/user/type",
  					data:{
  						
  					},
    				async: false,
    				dataType: "json",
     				xhrFields: {withCredentials: true},
    				crossDomain:true,
    				success: function(res) {
    					console.log("sssss")
    					console.log(res)
						if(res.code==0)
						{
							type=res.data;//0是老师，1是学生
							//$("#welcomTex").append("<button id='yes_btn' style='font-size: .35rem;position: absolute ;top:15%;right: 2%;background: none;border: none;' >退出</button>");
						}else{
							window.location.href="login.html"
						}
    				},
    				async:false
     			});
     			
			}
			function go(str){
				//window.location.href="login.html?surveyId="+str;
			}
			var result=[];
			function from() {				 
				$.ajax({
					type: "get",
					url:ip+"/client/person",
					data: {
						submitId:id
					},
					async: true,
					dataType: "json",
					xhrFields: {withCredentials: true},
      				crossDomain:true,
					success: function(res) {
						console.log(res)
						if(!res.code)
						{
							$.each(res.data, function(index, value) {
								if(index == '调查名称'||index=='section') {
									
								}else{
									result.push(value);
								}
							});
						setTitle(res.data.调查名称);
						dealStr(result);							
						var href="<a style='text-decoration: none;color:rgb(80, 169, 189);text-decoration:underline;display: block;font-size:.3rem;margin-top:2%' href='"+link[res.data.section]+"'>"+"部门官网 ：  "+res.data.section+"</a>"
						$("#title").append(href)}	
						
					},
					Error: function() {
						alert("服务器出错");
					}
				});
			}
			
			var content;
			function dealStr(arr) {
				content = ''
				$.each(arr, function(index, value) {
					for(one in value) {
						var ans=value[one];
						one=one.split("}")[0]
						var str1 = one.split(',"options":');
						var strArr=str1[1].split("],");
						var strArr1=strArr[1].split(",");
						//题目
						var obj = {};
						obj.orderNum = (strArr1[0].split(":"))[1];
						obj.type = (strArr1[2].split(":"))[1].split('"')[1];
						obj.required = (strArr1[1].split(":"))[1];
						obj.issue = (str1[0].split(":"))[1].split('"')[1];
						console.log(ans);
						if(ans!= null) {
							obj.answer = (ans.split("."))[0];
						}
						else {
							obj.answer = '';
						}
						console.log(obj.answer)
						//选项
						var strArr2 =strArr[0].split("[")[1].split('"');
						var optArr = [];
						console.log("ddddd")
						for(var i = 1; i <= strArr2.length; i++) {
							var opt = {};
							if(strArr2[i - 1].split(".").length>1){
							opt.option = (strArr2[i - 1].split("."))[0];
							opt.text = (strArr2[i - 1].split("."))[1];
							
							//	consosle.log(opt);
							optArr.push(opt);
							}
						}

						obj.option = optArr;
						console.log(obj);
						console.log(index)

						if(obj.type == 'Single') {
							content = content + buildSingle(obj);
						} else {
							content = content + buildInput(obj);
						}
					}
				});
				$("#ques-content").html(content);
			}
			function setTitle(data) {
				$("#title").html(data);
			}

			//生成副标题
			function buildSubheader(data) {
				return "<div id='ques-subhead'>" + data + "</div>"
			}
			
			var talg=0;
			//生成单选题
			function buildSingle(data) {
				//生成题目的前、后部分
				var front = "<div class='block full'>",
					end = "</div>";
				//生成总选项的前、后部分
				var quesFrontContent = "<div class='form-group' style='font-size: 20px;'><div class='row'><div class='col-md-9' id='form'" + data.nodeNum + ">",
					quesEndContent = "</div></div></div>";
				//生成每个选项的前、后部分
				var frontItem = "<div class='radio'>",
					quesItem = "",
					endItem = "</div>";

				var quesTitle = "<div style='font-size:.4rem;margin:0 0 5% 0'>" + data.orderNum + "." + data.issue + "</div>";

				//遍历一个问题的子节点
				for(var j = 0; j < data.option.length; j++) {
					if(data.option[j].option == data.answer) {
						var item = "<label style='padding: .1rem;border:1px solid #076eea;font-size: .38rem;border-radius: .15rem;margin: 2% 0 0 0;background: #79d3ff3d;' class='cssradios cssradios-primary' for='" + talg + "'><input type='radio' id='" + talg + "' name='radio" + data.orderNum + "' value='" + data.option[j].option + "' checked><span></span>" + data.option[j].text + "</label>";
					} else {
						var item = "<label class='cssradios cssradios-primary' for='" + talg + "'><input disabled type='radio' id='" + talg + "' name='radio" + data.orderNum + "' value='" + data.option[j].option + "'><span></span>" + data.option[j].text + "</label>";
					}
					talg++;
					quesItem = quesItem + frontItem + item + endItem;

				}
				var quesContent = quesFrontContent + quesItem + quesEndContent;
				var ques = front + quesTitle + quesContent + end;
				//返回时生成的html字符串

				return ques;
			}

			//生成填空题
			function buildInput(data) {
				//生成题目的前、后部分
				var front = "<div class='block full'>",
					end = "</div>";
				//生成总选项的前、后部分
				var quesFrontContent = "<div class='form-group' style='font-size: 20px;'><div class='row'><div class='col-md-9' id='form'" + data.orderNum + ">",
					quesEndContent = "</div></div></div>";
				var quesTitle = "<div>" + data.orderNum + "." + data.issue + "</div>";
				var item = "<textarea disabled type='text' id='input"+data.orderNum+"' name='example-input' class='form-control' placeholder='"+data.answer+"'></textarea>";
				var ques = front + quesTitle + quesFrontContent + item + quesEndContent + end;
				var $this='#input'+data.orderNum;
				console.log($this);
				$($this).val(data.answer);
				//返回时生成的html字符串
				return ques;
			}
			
			
		</script>
	</head>
	<body style="background: rgb(248,248,248);">
		
		<div>
			<div onClick="javascript :history.back(-1);" style="font-size: .3rem;background: rgb(172, 230, 243);line-height: .6rem;"><a style="margin: 0 0 0 3%;">返回</a></div>
			<div style="margin: 3% auto 0">
				<h4 id="title" style="text-align: center;background: white;width: 95%;margin: 0 auto 2%; padding: 1% 0;"></h4>
				<div id="ques-content" style="background:white;padding: 3% 5% 2%;">
				</div>
				<div class="submits" >
				</div>
			<div style="text-align: center;text-decoration: none;margin: 2% auto 10%;"><a style="text-decoration: none;font-size: .32rem;" href="https://wj.qq.com/s/2953793/5f86/">有问题点击这里告诉我们</a></div>
	
			</div>
		</div>
	</body>
</html>
